package com.qiandw.myblog.service.impl;

import com.qiandw.myblog.entity.User;
import com.qiandw.myblog.mapper.UserMapper;
import com.qiandw.myblog.service.UserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户服务实现类
 *
 * @author KG
 */
@Service("userService")
public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implements UserService {

    @Override
    public void join(Map<String, Object> map, String field) {
        if (map == null || map.get(field) == null) {
            return;
        }
        Map<String, Object> joinColumns = new HashMap<>();
        //字段的值
        String linkfieldValue = map.get(field).toString();

        User user = this.getById(linkfieldValue);
        if (null == user) {
            return;
        }

        joinColumns.put("username", user.getUsername());
        joinColumns.put("email", user.getEmail());
        joinColumns.put("avatar", user.getAvatar());
        joinColumns.put("id", user.getId());

        map.put("author", joinColumns);
    }
}
